package com.example.map.myapplication.fragmentdemo1;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.squareup.otto.Bus;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by qundui on 2017/5/26.
 */

public class B extends Fragment {
    private TextView tv;
    Bus bus;
        final String[] rightData={"第一页内容","第二页内容","第三页内容"};
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
         tv=new TextView(getActivity());
        EventBus.getDefault().register(this);
//        bus=new Bus();
//        bus.register(this);
        return tv;
    }
    public TextView getTv() {
        return tv;
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void get(MeassageEvent meassageEvent){
        int pos = meassageEvent.getPos();
        Log.i("gsc"," 收到A fargment 消息"+pos);
        tv.setText(rightData[pos]);

    }
//    @Subscribe
//    public void onEvent(MeassageEvent event) {
//        tv.setText(rightData[event.getPos()]);
//    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
       // bus.unregister(this);
    }
}
